Getting Started with GitHub
This guide will walk you through setting up GitHub from scratch, creating your first repository, and understanding the basic workflow. Whether you're completely new to version control or just new to GitHub, this tutorial will get you up and running quickly.
Prerequisites
Before we begin, you'll need:
- A computer with internet access
- Basic familiarity with using a terminal/command prompt (helpful but not required)
- A text editor or IDE installed on your computer
Step 1: Create Your GitHub Account
- Sign Up Process
- Account Settings
- Profile Setup
- Navigate to github.com
- Click the "Sign up" button in the top right corner
- Enter your email address, create a strong password, and choose a username
- Complete the verification process (solve the puzzle)
- Choose your preferences for GitHub updates and notifications
- Verify your email address by clicking the link sent to your inbox
After creating your account, configure these essential settings:
- Two-Factor Authentication (2FA): Enable 2FA for enhanced security
- SSH Keys: Add SSH keys for secure, password-free authentication
- Notification Preferences: Configure how you want to receive notifications
- Privacy Settings: Control the visibility of your profile and activity
Complete your profile to make a good impression:
- Profile Photo: Upload a professional photo or avatar
- Bio: Write a brief description of yourself and your interests
- Location: Add your location (optional)
- Website/Blog: Link to your personal website or portfolio
- Social Links: Connect your Twitter, LinkedIn, or other social accounts
Step 2: Install Git
Git is the version control system that powers GitHub. You'll need it installed on your computer to work with repositories locally.
- Windows
- macOS
- Linux
- Download Git from git-scm.com
- Run the installer with default settings (recommended for beginners)
- Open Command Prompt or PowerShell and verify installation:
git --version
Option 1: Using Homebrew (Recommended)
brew install git
Option 2: Download Installer
- Download from git-scm.com
- Run the installer
- Verify installation in Terminal:
git --version
Ubuntu/Debian:
sudo apt update
sudo apt install git
CentOS/RHEL/Fedora:
sudo yum install git
Verify installation:
git --version
Step 3: Configure Git
After installing Git, configure it with your GitHub credentials:
# Set your name (use your real name)
git config --global user.name "Your Name"
# Set your email (use the same email as your GitHub account)
git config --global user.email "[email protected]"
# Set default branch name to 'main'
git config --global init.defaultBranch main
# Verify your configuration
git config --list
Step 4: Create Your First Repository
- Via GitHub Web
- Via Command Line
- Click the "+" icon in the top right corner of GitHub
- Select "New repository"
- Fill in the repository details:
- Repository name: Choose a descriptive name (e.g., "my-first-repo")
- Description: Brief description of your project (optional)
- Visibility: Choose Public or Private
- Initialize: Check "Add a README file"
- License: Choose a license if desired
- Click "Create repository"
# Create a new directory for your project
mkdir my-first-repo
cd my-first-repo
# Initialize a Git repository
git init
# Create a README file
echo "# My First Repository" > README.md
# Add the file to staging
git add README.md
# Make your first commit
git commit -m "Initial commit"
# Add GitHub as remote origin (replace with your repository URL)
git remote add origin https://github.com/yourusername/my-first-repo.git
# Push to GitHub
git push -u origin main
Step 5: Clone Your Repository
To work with your repository locally, you'll need to clone it:
# Clone your repository
git clone https://github.com/yourusername/my-first-repo.git
# Navigate to the repository directory
cd my-first-repo
# List files to confirm successful clone
ls -la
Step 6: Basic Git Workflow
Now that you have a repository, learn the basic workflow:
- Basic Workflow
- Common Commands
- Make changes: Edit files in your repository
- Check status:
git status
- Stage changes:
git add filename
orgit add .
- Commit changes:
git commit -m "Description of changes"
- Push to GitHub:
git push
Command | Description |
---|---|
git status | Check the status of your working directory |
git add . | Stage all changes for commit |
git commit -m "message" | Commit staged changes with a message |
git push | Push commits to GitHub |
git pull | Pull latest changes from GitHub |
git log | View commit history |
Step 7: Understanding GitHub Interface
Familiarize yourself with the GitHub web interface:
- Code Tab: View your repository files and folders
- Issues Tab: Track bugs, features, and tasks
- Pull Requests Tab: Review and merge code changes
- Actions Tab: Automate workflows and CI/CD
- Projects Tab: Organize and track project progress
- Settings Tab: Configure repository settings
Next Steps
Now that you have the basics down, consider exploring:
- Branching: Learn to create and work with branches
- Pull Requests: Practice the collaboration workflow
- Issues: Use GitHub's issue tracking system
- GitHub Actions: Automate your workflows
- Open Source: Contribute to open-source projects
Troubleshooting Common Issues
- Authentication
- Push/Pull Issues
- Merge Conflicts
Problem: Authentication failures when pushing to GitHub
Solutions:
- Use Personal Access Tokens instead of passwords
- Set up SSH keys for password-free authentication
- Use GitHub CLI for authentication: Run
gh auth login
in terminal and follow the prompts - Check if your credentials are correctly configured
GitHub CLI Authentication Steps:
# Install GitHub CLI (if not already installed)
# Download from: https://cli.github.com/
# Authenticate with GitHub
gh auth login
# Follow the prompts to:
# 1. Choose authentication method (browser or token)
# 2. Select preferred protocol (HTTPS or SSH)
# 3. Complete authentication in browser or enter token
# Verify authentication
gh auth status
Problem: Unable to push or pull from repository
Solutions:
- Check your internet connection
- Verify repository URL:
git remote -v
- Ensure you have proper permissions to the repository
- Try:
git pull
before pushing
Problem: Merge conflicts when pulling or merging
Solutions:
- Use
git status
to identify conflicted files - Edit files to resolve conflicts manually
- Use a merge tool:
git mergetool
- Stage resolved files:
git add filename
- Complete the merge:
git commit